<template>
	<view>
		<u-navbar :safeAreaInsetTop="true" title="积分抽奖" autoBack :bgColor="'rgba(255,255,255,'+opc+')'" placeholder>

		</u-navbar>
		<image src="/static/common/bg.png" class="pagebg" mode=""></image>
		<view class="con">
			<view class="con__title">
				<view class="">
					<text class="con__num">{{userInfo.score}}</text>积分
				</view>
				<view class="">
					抽奖赢好礼
				</view>
			</view>
			<image src="/static/points/hbb.png" class="con__hb" mode=""></image>
			<view class="con__box">
				<image src="/static/points/cjbg.png" class="con__box__bg" mode=""></image>
				<view class="con__box__title">
					10积分抽奖一次
				</view>
				<view class="con__box__cj">
					<view class="con__box__cj__i">
						<view :class="timer==0?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[0].name}}
							</view>
						</view>
						<view :class="timer==1?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[1].name}}
							</view>
						</view>
						<view :class="timer==2?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[2].name}}
							</view>
						</view>
					</view>
					<view class="con__box__cj__i">
						<view :class="timer==3?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[3].name}}
							</view>
						</view>
						<!-- <view class="con__box__item">
							
						</view> -->
						<view @click="start" class=""
							style="width: 150rpx;height: 150rpx;border-radius: 100px;background-color: #EA6954;display: flex;flex-direction: column;align-items: center;justify-content: center;box-shadow: 2px 4px 6px #f3f3f3;">
							<view class="" style="color: white;color: #E9E4B4;font-size: 30rpx;">
								点击抽奖
							</view>
							<view class="" style="font-size: 20rpx;color: white;">
								消耗10积分
							</view>
						</view>
						<view :class="timer==4?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[4].name}}
							</view>
						</view>
					</view>
					<view class="con__box__cj__i">
						<view :class="timer==5?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[5].name}}
							</view>
						</view>
						<view :class="timer==6?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[6].name}}
							</view>
						</view>
						<view :class="timer==7?'con__box__item border':'con__box__item'">
							<view class="con__box__item__top">

							</view>
							<image src="/static/points/xhb.png" class="con__box__item__icon" mode=""></image>
							<view class="con__box__item__text">
								{{list[7].name}}
							</view>
						</view>
					</view>
				</view>
				<view class="con__box__list">
					<view class="" style="padding:0 30rpx;">
						<view class="" style="color: #88655F;font-weight: 600;display: flex;align-items: center;">
							<view class=""
								style="height: 36rpx;width: 6rpx;background-color: #F76361;border-radius: 100rpx;margin-right: 10rpx;">

							</view>
							<text style="font-size: 38rpx;">抽奖记录</text>
						</view>
						<view class="list">
							<u-empty mode="data"
								icon="http://jie.fuliaoxx.com/uploads/20250921/a97ed149994da025feb57f6fadc5ad44.jpg"
								v-if="list2.length==0">
							</u-empty>
							<view class="line" v-for="(item,index) in list2" :key="index">
								<view class="">
									<view class="" style="color: #976A62;font-weight: 600;font-size: 32rpx;">
										{{item.drawinfo.name}}
									</view>
									<view class="" style="color: #A09E9E;font-size: 24rpx;margin-top: 6rpx;">
										{{formatTimestamp(item.createtime)}}
									</view>
								</view>
								<view class="" style="color: #F76765;font-weight: 600;font-size: 40rpx;">
									-10
								</view>
							</view>
						</view>
					</view>
					<!-- <image src="/static/post/cjjl.png" style="width: 750rpx;" mode="widthFix"></image> -->
				</view>
			</view>
		</view>
		<u-modal :show="show" title="抽奖结果" :content='content' @confirm="show=false" confirmText="确认"></u-modal>
	</view>
</template>

<script>
	import {
		drawList,
		draw,
		getUserDraw
	} from "@/request/api/pointer.js"
	import {
		userInfo
	} from "@/request/api/my.js"
	export default {
		data() {
			return {
				show: false,
				content: "",
				opc: 0,
				list: [],
				list2: [],
				timer: -1,
				numer: 4,
				callTimer: null,
				userInfo: {
					score: 0
				},
			};
		},
		onPageScroll(e) {
			if (e.scrollTop == 0) {
				this.opc = 0
			} else {
				this.opc = 1
			}
		},
		methods: {
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒
				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');
				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
			},
			start() {
				if (this.userInfo.score < 10) {
					uni.showToast({
						icon: "none",
						title: "积分不足"
					})
					return
				}
				uni.showLoading({
					mask: true
				})
				draw().then(res1 => {
					console.log(res1)
					this.content = res1.data.name;
					userInfo().then(res => {
						this.userInfo = res.data;
					})
				})
				this.timer = 0;

				this.callTimer = setInterval(() => {
					if (this.timer == 7) {
						if (this.numer == 1) {
							clearInterval(this.callTimer);
							this.callTimer = null;
							this.timer = -1;
							this.numer = 4;
							uni.hideLoading()
							getUserDraw().then(res => {
								this.show = true;
								this.list2 = res.data;
							})
						} else {
							this.numer -= 1;
							this.timer = 0;
						}
					} else {
						this.timer += 1;
					}

				}, 50)
			}
		},
		onLoad() {
			drawList().then(res => {
				this.list = res.data;
			})
			userInfo().then(res => {
				this.userInfo = res.data;
			})
			getUserDraw().then(res => {
				this.list2 = res.data;
			})
		}
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: content-box;
	}

	.border {
		scale: 1.1;
	}

	.list {
		margin-top: 20rpx;
		border: 4rpx solid #EBA079;
		// min-height: 200rpx;
		border-radius: 14rpx;
		padding: 10rpx 20rpx;

		.line {
			padding: 20rpx 0;
			border-bottom: 1rpx solid #d6916e;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}

	.con {
		// background-color: #fde5e2;
		position: relative;

		&__title {
			font-family: AlimamaShuHeiTi;
			font-weight: bold;
			font-size: 70rpx;
			color: #1E1E1E;
			line-height: 81rpx;
			padding: 28rpx 0 0 42rpx;
		}

		&__num {
			font-family: DINNextLTPro;
			font-weight: bold;
			font-size: 93rpx;
			color: #FF5153;
			line-height: 81rpx;
		}

		&__hb {
			width: 238rpx;
			height: 266rpx;
			position: absolute;
			top: 0;
			right: 30rpx;
		}

		&__box {
			width: 750rpx;
			height: 1515rpx;
			position: relative;

			&__bg {
				width: 750rpx;
				height: 1515rpx;
				position: absolute;
				top: 0;
				left: 0;
			}

			&__title {
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #FFF6E7;
				line-height: 30rpx;
				position: absolute;
				left: 128rpx;
				top: 21rpx;
			}

			&__cj {
				width: 526rpx;
				height: 526rpx;
				padding: 143rpx 112rpx 61rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				&__i {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
			}

			&__item {
				width: 162rpx;
				height: 153rpx;
				background: #F7FBF9;
				border-radius: 15rpx 15rpx;
				position: relative;

				&__icon {
					width: 65rpx;
					height: 77rpx;
					position: absolute;
					top: 24rpx;
					left: 50rpx;
				}

				&__text {
					width: 162rpx;
					height: 43rpx;
					background: #EBE3B3;
					box-shadow: 2rpx 0rpx 0rpx 0rpx #D9A957;
					border-radius: 0rpx 0rpx 20rpx 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #543C12;
					line-height: 24rpx;
					position: absolute;
					bottom: 0;
					left: 0;
				}

				&__top {
					width: 162rpx;
					height: 20rpx;
					background: #EBE3B3;
					border-radius: 20rpx 20rpx 0rpx 0rpx;
					position: absolute;
					top: 0;
					left: 0;
				}
			}

			&__list {
				width: 750rpx;
				height: 650rpx;
				position: relative;
				margin-top: 136rpx;

				&__title {
					display: flex;
					align-items: center;

				}
			}
		}
	}
</style>